﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Reflection;

public partial class Manage_Default : ManagePageBase
{
    int paperid = 0;
    protected void Page_Load(object sender, EventArgs e) {

        Button1.Text = Resources.labels.DefaultSetOrder;

        if (!IsPostBack)
        {
            string currpaperid = Tools.ReadText(Server.MapPath("~/App_Data/currentpaper.txt"));
            if (int.TryParse(currpaperid, out paperid))
            {
                if (paperid > 0)
                {
                    Exam.Core.Model.Paper paper = new Exam.Core.DAL.Paper().getPaperById(paperid);
                    Label1.Text = "<a href=\"paper.aspx?id=" + paper.PaperID + "\" target=_blank title=\"点击预览该试卷\">" + paper.PaperName + "</a>";
                    List<Exam.Core.Model.PaperQuestionType> model = paper.PaperQuestionTypes;
                    if (model == null)
                        return;
                    StringBuilder sb = new StringBuilder();
                    float total = 0;
                    int totalCount = 0;
                    foreach (Exam.Core.Model.PaperQuestionType o in model)
                    {
                        sb.Append(o.QuestionTypeTitle.Trim() + o.QuestionCount.Trim() + "，");
                        total = total + float.Parse(o.Score.Trim()) * int.Parse(o.QuestionCount.Trim());
                        totalCount = totalCount + int.Parse(o.QuestionCount.Trim());
                    }
                    string tmp = Resources.labels.paper_qtotal_score;
                    tmp = string.Format(tmp,totalCount,total);
                    sb.Append(tmp);

                    litTj.Text = sb.ToString();
                }
                else
                {
                    Label1.Text = Resources.labels.noCurrentPaper;
                }

            }
            //.txt
            string ExRegulation = Tools.ReadText(Server.MapPath("~/App_Data/ExRegulation.txt"));
            TextBox1.Text = Server.HtmlDecode(ExRegulation);

        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string ExRegulation = Server.HtmlEncode(TextBox1.Text);
        Tools.WriteTxt(ExRegulation, Server.MapPath("~/App_Data/ExRegulation.txt"));
    }
}
